import Vue from 'vue'
import Router from 'vue-router'
// 路由懒加载
const Home = () => import('../views/Home.vue')
const Blog = () => import('../views/Blog.vue')
const Link = () => import('../views/Link.vue')
const Message = () => import('../views/Message.vue')
const Crawler = () => import('../views/crawler/Crawler.vue')
const Archives = () => import('../views/Archives.vue')
const Types = () => import('../views/type/Types.vue')
const Tags = () => import('../views/type/Tags.vue')
const AI = () => import('../views/backyard/AI.vue')
const Login = () => import('../views/admin/Login.vue')
const Admin_login = () => import('../views/admin/Admin_login.vue')
const About = () => import('../views/backyard/About.vue')
const Welcome=()=> import('../views/admin/Welcome')
const AdminHome=()=>import('../components/layout/AdminHome')
const Im=()=>import('../views/Im')
// import Users from '../views/admin/users/Users'


// import Users from '../views/admin/users/Users'
const Users = () => import(/* webpackChunkName: "Users" */ '../views/admin/users/Users')


const Report = () => import(/* webpackChunkName: "dataWatch" */ '../views/admin/dataWatch/Report')
const Report2 = () => import(/* webpackChunkName: "dataWatch" */ '../views/admin/dataWatch/Report2')

const Favorite= () => import('../views/admin/blogs/favorite')
const PostBlogs = () => import(/* webpackChunkName: "admin" */ '../views/admin/blogs/PostBlogs.vue')
const Blogs = () => import(/* webpackChunkName: "admin" */ '../views/admin/blogs/Blogs.vue')
const Types2 = () => import(/* webpackChunkName: "admin" */ '../views/admin/blogs/Types2.vue')
const Tags2 = () => import(/* webpackChunkName: "admin" */ '../views/admin/blogs/Tags2.vue')

const Music = () => import(/* webpackChunkName: "Music" */ '../views/Music.vue')
const Playlists = () => import(/* webpackChunkName: "Music" */ '../views/music/Playlists.vue')
const Mvs = () => import(/* webpackChunkName: "Music" */ '../views/music/Mvs.vue')
const Songs = () => import(/* webpackChunkName: "Music" */ '../views/music/Songs.vue')
const Discovery = () => import(/* webpackChunkName: "Music" */ '../views/music/Discovery.vue')
const Result = () => import(/* webpackChunkName: "Music" */ '../views/music/Result.vue')
const Mv = () => import(/* webpackChunkName: "Music" */ '../views/music/Mv.vue')
const Playlist = () => import(/* webpackChunkName: "Music" */ '../views/music/Playlist.vue')
Vue.use(Router)

const routes = [
  { path: '/', redirect: 'home' },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    meta: {
      title: '首页'
    }
  },
  {
    path: '/im',
    name: 'Im',
    component: Im,
    meta: {
      title: '聊天室'
    }
  },
  {
    path: '/Blog/:blogId',
    name: 'Blog',
    component: Blog,
    meta: {
      title: '博客详情'
    }
  },
  {
		path: '/types',
		name: 'types',
		component: Types,
		meta:{
			title:'分类',
		}
	},
  {
		path: '/tags',
		name: 'tags',
		component: Tags,
		meta:{
			title:'标签',
		}
	},
  {
		path: '/archives',
		name: 'archives',
		component: Archives,
		meta:{
			title:'归档',
		}
	},
  {
    path: '/link',
    name: 'Link',
    component: Link,
    meta: {
      title: '友链'
    }
  },
  {
		path: '/message',
		name: 'message',
		component: Message,
		meta:{
			title: '留言',
		}
	},
	{
		path: '/crawler',
		name: 'crawler',
		component: Crawler,
		meta:{
			title: '爬虫',
		}
	},
  {
		path: '/ai',
		name: 'ai',
		component: AI,
		meta:{
			title: '人工智能',
		}
	},
  {
    path: '/login',
    name: 'Login',
    component: Login,
    meta: {
      title: '用户登录'
    }
  },
  {
    path: '/admin_login',
    name: 'admin_login',
    component: Admin_login,
    meta: {
      title: '管理员登录'
    }
  },
  {
    path: '/about',
    name: 'about',
    component: About,
    meta:{
      title: '关于我们'
    }
  },{
    path: '/AdminHome',
    component: AdminHome,
    redirect: '/welcome',
    meta: {
      title: '博客后台管理'
    },
    children: [{ path: '/welcome', component: Welcome },
      { path: '/users', component: Users },
      { path: '/PostBlogs', component: PostBlogs },
      { path: '/Blogs', component: Blogs },
      { path: '/tags2', component: Tags2 },
      { path: '/types2', component: Types2 },
      { path: '/report', component: Report },
      { path: '/report2', component: Report2 },
      { path: '/favorite', component: Favorite}
    ]
  },{
    path: '/Music',
    name: 'Music',
    component: Music,
    children: [
      {
        // 发现音乐
        path: '/Discovery',
        component: Discovery
      },
      {
        // 推荐歌单
        path: '/Playlists',
        component: Playlists
      },
      {
        // 推荐歌单
        path: '/Playlist',
        component: Playlist
      },
      {
        // 最新音乐
        path: '/Songs',
        component: Songs
      },
      {
        // 最新音乐
        path: '/Mvs',
        component: Mvs
      },
      // mv详情
      {
        path: '/Mv',
        component: Mv
      },
      // 搜索结果页
      {
        path: '/Result',
        component: Result
      }
    ]
  }

]

const router = new Router({
  // 配置路由和组件之间的映射关系
  routes,
  // 切换为H5的history模式（url路径就没有#了，默认配置为hash模式）
  mode: 'history'
})

// 全局导航守卫
// 前置守卫（guard），跳转之前回调该函数
router.beforeEach((to, from, next) => {
  // 从from跳转到to
  document.title = to.matched[0].meta.title
  next()
})

export default router
